﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef BURNCTRLJLINKWORKER_H
#define BURNCTRLJLINKWORKER_H

#include <QObject>
#include <QProcess>
#include <QDir>
#include <QSettings>
#include "BurnToolCommon/Global.h"

namespace BurnCtrlJlinkWorkerClass {
class BurnCtrlJlinkWorker : public QObject {
    Q_OBJECT
public:
    explicit BurnCtrlJlinkWorker(QObject *parent = nullptr);
    void SetInfoArray(const QMap<int, BIN_INFO> &info);
    void StopProBurnStart() const;
public slots:
    void SlotEraseFlash();
    void SlotBurnFlash();
signals:
    void SignalEraseFlashSuccess(const QString &);
    void SignalEraseFlashFaild();
    void SignalBurnFlashSuccess();
    void SignalBurnFlashStr(const QString &);
    void SignalBurnFlashFaild();
    void SignalSetProgressValue(int pos);
protected:
    void EraseFlashType(int type);
    void BurnFlashScripts(QFile &file, QMap<int, BIN_INFO>::iterator index);
    void BurnFlashSetProgress(int oldPos, int index);
    void FileWriteScripts(const QSettings &cfg, const QString &saveDir, QFile &file);
    void BurnFlashFolder(QStringList &folder, const QStringList &cfgList, const QString &path,
                         const QSettings &cfg, const QString &saveDir) const;
    bool CmdWhitelisting(QPair<QString, QString> mapfolder) const;
private:
    QProcess *proBurnStart;
    QMap<int, BIN_INFO> infoArray;
};
}

#endif // BURNCTRLJLINKWORKER_H
